package com.vtc.session13;

import com.vtc.R;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Toast;

public class StudentAddDialog extends DialogFragment{

	public StudentListActivity parentForm;
	private EditText txtName,txtAddr,txtAge;
	@Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
	    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
	    builder.setTitle("Add Student Form");
	    LayoutInflater inflater = getActivity().getLayoutInflater();
	    LinearLayout layout =(LinearLayout ) inflater.inflate(R.layout.studentadd1_activity, null);
	    builder.setView(layout);
	    
	    txtName = (EditText) layout.findViewById(R.id.studentadd1_txtName);
	    txtAddr = (EditText) layout.findViewById(R.id.studentadd1_txtAddr);
	    txtAge  = (EditText) layout.findViewById(R.id.studentadd1_txtAge);
	    
	    builder.setPositiveButton("Save", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {				
				//Toast.makeText(getActivity(), str, Toast.LENGTH_LONG).show();
				String name = txtName.getText().toString();
				String addr = txtAddr.getText().toString();
				int age= Integer.parseInt(txtAge.getText().toString());
				Student st = new Student(name, addr, age);
				parentForm.adapter.add(st);
			}
		});
		builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				//Toast.makeText(getActivity(), "Cancel ", Toast.LENGTH_LONG).show();
			}
		});
		return builder.create();
	}
}
